import 'package:aichat_flutter_wallet/module_common/utils/colors.dart';
import 'package:flutter/cupertino.dart';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class BottomSheetWidget extends StatelessWidget {
  final String title;

  final Widget? action;

  final Widget child;

  final bool expand;

  final double bottomPadding;

  final VoidCallback? closeCallback;
  final bool showCloseBtn;

  const BottomSheetWidget(
      {super.key,
      required this.title,
      required this.child,
      this.expand = true,
      this.bottomPadding = 0,
      this.closeCallback,
      this.action,
      this.showCloseBtn = true});

  Widget titleWidget (BuildContext context) {
    TextStyle textStyle = TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w500, color: AppColors.c_333333);

    return SizedBox(
      height: 50.w,
      child: Stack(
        children: [
          Visibility(
              visible: showCloseBtn,
              child: GestureDetector(
                onTap: () {
                  if (null != closeCallback) {
                    closeCallback!.call();
                    return;
                  }
                  Navigator.of(context).pop();
                },
                child: Padding(
                    padding: EdgeInsets.only(top: 15.w, left: 20.w),
                    child: Image.asset(
                      'assets/images/common/dialog-close.png',
                      width: 20.w,
                      height: 20.w,
                    )),
              )),
          Center(
              child: Text(
                title,
                style: textStyle,
              )),
          Align(
            alignment: Alignment.centerRight,
            child: null == action
                ? const SizedBox(
              width: 0,
              height: 0,
            )
                : action!,
          )
        ],
      ),
    );
  }


  @override
  Widget build(BuildContext context) {
    Decoration decoration = BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.only(topLeft: Radius.circular(20.w), topRight: Radius.circular(20.w)));

    return expand
        ? Container(
            padding: EdgeInsets.only(bottom: bottomPadding),
            decoration: decoration,
            child: Column(
              children: [
                titleWidget(context),
                Expanded(child: child)
              ],
            ))
        : SizedBox(
            height: double.infinity,
            child: Stack(
              children: [
                Positioned(left: 0,right: 0,top: 0,bottom: 0,child: GestureDetector(
                  onTap: (){
                    if (null != closeCallback) {
                      closeCallback!.call();
                      return;
                    }
                    Navigator.of(context).pop();
                  },
                  child: Container(color: Colors.transparent,),)),
                Align(
                  alignment: Alignment.bottomCenter,
                  child:       Container(
                    padding: EdgeInsets.only(bottom: bottomPadding),
                    decoration: decoration,
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        titleWidget(context),
                        child
                      ],
                    ),
                  ) ,
                )
              ],
            ) ,
          );
  }
}
